'use strict';

//这样写: ...controller('mainCtrl',['$scope',function($scope){}]);
//可以防止,压缩js代码时 破坏掉依赖注入的名字
angular.module('app').controller('registerCtrl',['$scope','$http','$state','$interval',function($scope, $http, $state, $interval){
    $scope.submit = function(){
        $http.post('data/regist.json',$scope.user).then(function(resp){
            $state.go('login');
           
        });
       
    }
    var count = 60;
    $scope.send = function(){
        $http.get('data/code.json').then(function(resp){
            if(1 === resp.data.state){
                $scope.time = '60s';
                var interval = $interval(function(){
                    if(count<=0){
                        $interval.cancel(interval);
                        $scope.time='';
                        return;
                    } else {
                         count--;
                         $scope.time = count+'s';
                    }
                    
                },1000);
            }
        });
    }
}]);